package com.earthquake.monitor_system.controller;

import com.earthquake.monitor_system.controller.resultType.Pagination;
import com.earthquake.monitor_system.domain.SeismicInformation;
import com.earthquake.monitor_system.domain.UserDomain;
import com.earthquake.monitor_system.service.impl.SeismicInformationImpl;
import com.earthquake.monitor_system.utils.Result;
import com.earthquake.monitor_system.utils.urlData.URLdata;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/SeismicInfo")
public class SeismicInformationController {
    @Autowired
   private SeismicInformationImpl seismicInformationImpl;
    @PostMapping("/insert")
    public Result inset(@RequestBody SeismicInformation seismicInformation) throws Exception {
        Boolean insert = seismicInformationImpl.insert(seismicInformation);
        if(!insert) {
            return Result.warn("插入失败", null);
        }
        return Result.success("插入成功", true);
    }
    @GetMapping("/openBug")
    public Result openBug() {
       try {
           URLdata urLdata = new URLdata();
           urLdata.getdata();
       }catch (Exception e) {
           return Result.error("开启数据爬虫失败！", false);
       }
       return Result.success("开启数据爬虫成功！", true);
    }
    @PostMapping("/getSeismicInfoList")
    public Result querySeismicInfoList(@RequestBody Pagination pagination) {
        Object seismicInformations = seismicInformationImpl.querySeismicInfoList(pagination);
        return Result.success("获取数据成功",seismicInformations);
    }
    @GetMapping("getCoordinatePoint")
    public Result getCoordinatePoint( String timeStamp) {
        List<SeismicInformation> getCoordinatePointList = seismicInformationImpl.getCoordinatePoint(timeStamp);
        return Result.success("获取数据成功",getCoordinatePointList);
    }
    @GetMapping("/getEarthquakeMagnitudek")
    public Result getEarthquakeMagnitudek(){
        List earthquakeMagnitudek = seismicInformationImpl.getEarthquakeMagnitudek();
        return  Result.success("获取数据成功",earthquakeMagnitudek);
    }
    @DeleteMapping("/deleteById")
    public Result deleteById(String id) {
        Boolean aBoolean = seismicInformationImpl.deleteById(id);
        return Result.success("请求成功",aBoolean);
    }

}
